package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.CustomerAccount;
import com.urea.system.service.ICustomerAccountService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 客户/车队账户Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/customer/account")
public class CustomerAccountController extends BaseController
{
    @Autowired
    private ICustomerAccountService customerAccountService;

    /**
     * 查询客户/车队账户列表
     */
    @PreAuthorize("@ss.hasPermi('customer:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerAccount customerAccount)
    {
        startPage();
        List<CustomerAccount> list = customerAccountService.selectCustomerAccountList(customerAccount);
        return getDataTable(list);
    }

    /**
     * 导出客户/车队账户列表
     */
    @PreAuthorize("@ss.hasPermi('customer:account:export')")
    @Log(title = "客户/车队账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerAccount customerAccount)
    {
        List<CustomerAccount> list = customerAccountService.selectCustomerAccountList(customerAccount);
        ExcelUtil<CustomerAccount> util = new ExcelUtil<CustomerAccount>(CustomerAccount.class);
        util.exportExcel(response, list, "客户/车队账户数据");
    }

    /**
     * 获取客户/车队账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(customerAccountService.selectCustomerAccountById(id));
    }

    /**
     * 新增客户/车队账户
     */
    @PreAuthorize("@ss.hasPermi('customer:account:add')")
    @Log(title = "客户/车队账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerAccount customerAccount)
    {
        return toAjax(customerAccountService.insertCustomerAccount(customerAccount));
    }

    /**
     * 修改客户/车队账户
     */
    @PreAuthorize("@ss.hasPermi('customer:account:edit')")
    @Log(title = "客户/车队账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerAccount customerAccount)
    {
        return toAjax(customerAccountService.updateCustomerAccount(customerAccount));
    }

    /**
     * 删除客户/车队账户
     */
    @PreAuthorize("@ss.hasPermi('customer:account:remove')")
    @Log(title = "客户/车队账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerAccountService.deleteCustomerAccountByIds(ids));
    }
}
